package com.smarthome.web.property.controller.workingmonitor;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.smarthome.core.workingmonitor.DeviceStateService;
import com.smarthome.domain.bean.ShEquipmentStatus;
import com.smarthome.domain.vo.boss.TimeRange;
import com.smarthome.domain.vo.boss.Combobox;
import com.smarthome.domain.vo.boss.DataGrid;
import com.smarthome.domain.vo.boss.PageHelper;
import com.smarthome.web.property.utils.UserHolder;
/**
 * 
* @ClassName: DeviceStateLogController
* @Description: 设备状态控制类
* @author cyj
* @date 2015年10月7日 下午5:00:36
*
 */
@Controller
@RequestMapping("/deviceStateController")
public class DeviceStateController {

	@Resource
	private DeviceStateService deviceStateService;
	
	
	/**
	 * 
	* @Title: getPage 
	* @Description: TODO(根据条件获取系统运行状态数据列表) 
	* @param sysHeartbeat
	* @param timeRange
	* @param helper
	* @return
	* DataGrid
	* @throws 
	* @author cyj
	 */
	@RequestMapping("/dataGrid")
    @ResponseBody
	public DataGrid getPage(ShEquipmentStatus shEquipmentStatus,TimeRange timeRange,PageHelper helper){
		if(timeRange.getStartGmtCreate() != null) {
			shEquipmentStatus.addQueryData("startGmtCreate", timeRange.getStartGmtCreate());
		}
		if(timeRange.getEndGmtCreate() != null) {
			shEquipmentStatus.addQueryData("endGmtCreate", timeRange.getEndGmtCreate());
		}
		Long residenceId = UserHolder.getCurrentResidenceId();
		shEquipmentStatus.addQueryData("residenceId", residenceId);
		return deviceStateService.dataGrid(shEquipmentStatus, helper);
	}
	
	
	/**
	 * 
	* @Title: getComboData 
	* @Description: 获取设备状态查询需要的combo数据
	* @return
	* Map<String,Object>
	* @throws 
	* @author cyj
	 */
	@RequestMapping("/getComboData")
    @ResponseBody
	public Map<String,Object> getComboData() {
    	Map<String,Object> result = new HashMap<>();
    	List<Combobox> equipmentType = deviceStateService.equipmentTypeCombobox();
    	List<Combobox> status = deviceStateService.statusCombobox();
    	result.put("equipmentType", equipmentType);
    	result.put("status", status);
    	return result;
    }
}
